package com.jcfy.project.module.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcfy.framework.aspectj.lang.annotation.Log;
import com.jcfy.framework.aspectj.lang.enums.BusinessType;
import com.jcfy.project.module.domain.TSupplier;
import com.jcfy.project.module.service.ITSupplierService;
import com.jcfy.framework.web.controller.BaseController;
import com.jcfy.framework.web.domain.AjaxResult;
import com.jcfy.common.utils.poi.ExcelUtil;
import com.jcfy.framework.web.page.TableDataInfo;

/**
 * 供应商Controller
 *
 * @author jiangfeng
 * @date 2020-08-05
 */
@RestController
@RequestMapping("/module/supplier" )
public class TSupplierController extends BaseController {
    @Autowired
    private ITSupplierService tSupplierService;

    /**
     * 查询供应商列表
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(TSupplier tSupplier) {
        startPage();
        List<TSupplier> list = tSupplierService.selectTSupplierList(tSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:export')" )
    @Log(title = "供应商" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TSupplier tSupplier) {
        List<TSupplier> list = tSupplierService.selectTSupplierList(tSupplier);
        ExcelUtil<TSupplier> util = new ExcelUtil<TSupplier>(TSupplier. class);
        return util.exportExcel(list, "supplier" );
    }

    /**
     * 获取供应商详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:query')" )
    @GetMapping(value = "/{supplierId}" )
    public AjaxResult getInfo(@PathVariable("supplierId" ) Long supplierId) {
        return AjaxResult.success(tSupplierService.selectTSupplierById(supplierId));
    }

    /**
     * 新增供应商
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:add')" )
    @Log(title = "供应商" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSupplier tSupplier) {
        return toAjax(tSupplierService.insertTSupplier(tSupplier));
    }

    /**
     * 修改供应商
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:edit')" )
    @Log(title = "供应商" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSupplier tSupplier) {
        return toAjax(tSupplierService.updateTSupplier(tSupplier));
    }

    /**
     * 删除供应商
     */
    @PreAuthorize("@ss.hasPermi('module:supplier:remove')" )
    @Log(title = "供应商" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}" )
    public AjaxResult remove(@PathVariable Long[] supplierIds) {
        return toAjax(tSupplierService.deleteTSupplierByIds(supplierIds));
    }
}
